//
//  AnswerDetailCommentsCell.m
//  OnionHome
//
//  Created by fengjie on 2019/9/20.
//  Copyright © 2019 FengJie. All rights reserved.
//

#import "AnswerDetailCommentsCell.h"
#import "AnswerDetailAllCommentsVC.h"

#pragma mark --含有二级评论的cell
@interface AnswerDetailCommentsCell ()
/**<#属性#>*/
@property (nonatomic,strong)UILabel * oneLabel;
/**二级评论数据*/
@property (nonatomic,strong)UILabel*twoCommen;
/**查看个数*/
@property (nonatomic,strong)UILabel*commenNumber;
/**<#属性#>*/
@property (nonatomic,strong)UILabel*numberLabel;
/**<#属性#>*/
@property (nonatomic,strong)UIView * contenView;
@end

@implementation AnswerDetailCommentsCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self createUI];
    }
    return self;
}
-(void)setNumberStr:(NSString *)numberStr{
    _numberStr = numberStr;
    
}
-(void)setCommenModel:(UserCommentsModel *)commenModel{
    _commenModel = commenModel;
    [TitleTool setTwoCommenUserName:commenModel.twoName contTitle:commenModel.twoText Label:self.twoCommen];
    if (!StrValid(commenModel.oneName)) {
        return;
    }
    self.topView.userName.text = commenModel.oneName;
    self.topView.iconImage.image = IMAGE_NAMED(commenModel.oneUserIcon);
    [self.topView.deleButton setTitle:commenModel.zanNum forState:UIControlStateNormal];
    self.topView.deleButton.selected = commenModel.isZan;
    self.oneLabel.text = commenModel.oneText;
    self.numberLabel.text = [NSString stringWithFormat:@"%@  %@ 回复",commenModel.dataTime,commenModel.twoAllnum];
    self.authorLb.hidden = !commenModel.isAuthor;
    
//    self.twoCommen.text = [NSString stringWithFormat:@"%@:%@",commenModel.twoName,commenModel.twoText];
    
    self.commenNumber.text = [NSString stringWithFormat:@"查看全部%@条回复",commenModel.twoAllnum];
}
-(void)createUI{
    
    self.oneLabel = UILabel.new;
    self.oneLabel.textColor = UIColorFromRGB(0x273323);
    self.oneLabel.font = SYSTEMFONT(16);
    self.oneLabel.numberOfLines = 0;
    self.oneLabel.text = @"这里是我的评论，大家来点赞！";
    
    self.numberLabel = UILabel.new;
    self.numberLabel.textColor = UIColorFromRGB(0x454F44);
    self.numberLabel.font = SYSTEMFONT(12);
    self.numberLabel.numberOfLines = 0;
    self.numberLabel.text = @"2019-04-19  15:30  24回复";
    
    self.contenView = [self createContenView];
    
    
    [self addSubview:self.topView];
    [self addSubview:self.oneLabel];
    [self addSubview:self.numberLabel];
    [self addSubview:self.contenView];
    [self addSubview:self.reportBtn];
    
    [self.topView addSubview:self.authorLb];
    
    
    
    [self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.mas_equalTo(0);
    }];
    
    [self.oneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(70);
        make.right.mas_equalTo(-16);
        make.top.mas_equalTo(self.topView.mas_bottom);
    }];
    
    [self.contenView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(self.oneLabel);
        make.top.mas_equalTo(self.oneLabel.mas_bottom).offset(14);
    }];
    
    [self.numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(70);
        make.right.mas_equalTo(-16);
        make.top.mas_equalTo(self.contenView.mas_bottom).offset(8);
        make.bottom.mas_equalTo(-16);
    }];
    [self.reportBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-16);
        make.centerY.mas_equalTo(self.numberLabel);
    }];

    
    [self.authorLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.topView.userName.mas_right).offset(10);
        make.centerY.mas_equalTo(self.topView.userName);
        make.width.mas_equalTo(28);
        make.height.mas_equalTo(16);
    }];
}
-(UserIconAndNameView*)topView{
    if(!_topView){
        _topView=[[UserIconAndNameView alloc] initWithFrame:CGRectZero];
        _topView.dynamicData.text = @"美食达人";
        [_topView.deleButton setImage:IMAGE_NAMED(@"ic_like_defut") forState:UIControlStateNormal];
        [_topView.deleButton setBackgroundImage:nil forState:UIControlStateNormal];
        [_topView.deleButton setTitle:@"13" forState:UIControlStateNormal];
        [_topView.deleButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 4, 0, -4)];
        [_topView.deleButton setTitleColor:UIColorFromRGB(0x454F44) forState:UIControlStateNormal];
        _topView.deleButton.titleLabel.font = SYSTEMFONT(12);
        [_topView.deleButton addActionHandler:^{
            
        }];
    }
    return _topView;
}
-(UILabel*)authorLb{
    if(!_authorLb){
        _authorLb=[UILabel new];
        _authorLb.textColor = UIColorFromRGB(0x2B77EC);
        _authorLb.font = SYSTEMFONT(11);
        _authorLb.text = @"作者";
        ViewBorderRadius(_authorLb, 2, 0.5, UIColorFromRGB(0x2B77EC));
        _authorLb.textAlignment = NSTextAlignmentCenter;
    }
    return _authorLb;
}
-(UILabel*)twoCommen{
    if(!_twoCommen){
        _twoCommen=[UILabel new];
        _twoCommen.textColor = UIColorFromRGB(0x363647);
        _twoCommen.font = BOLDSYSTEMFONT(14);
        _twoCommen.numberOfLines = 0;
        _twoCommen.text = @"孤独的恒星:如果你无法简洁的表达你的想法，那只说明你还不够了解它。真理惟一可靠的标准就是永远自相符合。";
    }
    return _twoCommen;
}
-(UILabel*)commenNumber{
    if(!_commenNumber){
        _commenNumber=[UILabel new];
        _commenNumber.textColor = UIColorFromRGB(0x2B77EC);
        _commenNumber.font = SYSTEMFONT(12);
        _commenNumber.userInteractionEnabled = YES;
        _commenNumber.text = @"查看全部24条回复";
        [_commenNumber addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(pushAllAction)]];
    }
    return _commenNumber;
}
-(UIButton*)reportBtn{
    if(!_reportBtn){
        _reportBtn=[UIButton buttonWithType:UIButtonTypeCustom];
        [_reportBtn setTitleColor:UIColorFromRGB(0x959E97) forState:UIControlStateNormal];
        _reportBtn.titleLabel.font = SYSTEMFONT(12);
        [_reportBtn setTitle:@"举报" forState:UIControlStateNormal];
        _reportBtn.hidden = YES;
    }
    return _reportBtn;
}
-(UIView *)createContenView{
    UIView * view = UIView.new;
    view.backgroundColor = UIColorFromRGB(0xF5F7F5);
    [view addSubview:self.twoCommen];
    [view addSubview:self.commenNumber];
    
    [self.twoCommen mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.mas_equalTo(12);
        make.right.mas_equalTo(-12);
    }];
    [self.commenNumber mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(12);
        make.right.bottom.mas_equalTo(-12);
        make.top.mas_equalTo(self.twoCommen.mas_bottom).offset(5);
    }];
    
    return view;
}
-(void)pushAllAction{
    if (self.commenModel.isVideo) {
        PresentationObject * object = [PresentationObject sharedPresentationObject];
        object.subViewFrame = CGRectMake(0, 210, KScreenWidth, KScreenHeight-210);
//        object.alpha_bgView = -1;
        [object showPresentingViewController:[self getCurrentViewController] PresentedViewController:[[BasseNavigationController alloc] initWithRootViewController:[AnswerDetailAllCommentsVC new]]];
    }else{
        AnswerDetailAllCommentsVC * vc = [AnswerDetailAllCommentsVC new];
        vc.isFullScreen = YES;
        [[self getCurrentViewController] presentViewController:[[BasseNavigationController alloc] initWithRootViewController:vc] animated:YES completion:nil];
    }
}
@end


#pragma mark ---只有一级评论的cell
@interface AnswerDetailCommentsOneCell ()

/**<#属性#>*/
@property (nonatomic,strong)UILabel * oneLabel;
/**<#属性#>*/
@property (nonatomic,strong)UILabel*numberLabel;

@end


@implementation AnswerDetailCommentsOneCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self createUI];
    }
    return self;
}
-(void)setCommenModel:(UserCommentsModel *)commenModel{
    _commenModel = commenModel;
    self.topView.userName.text = commenModel.oneName;
    self.topView.iconImage.image = IMAGE_NAMED(commenModel.oneUserIcon);
    [self.topView.deleButton setTitle:commenModel.zanNum forState:UIControlStateNormal];
    self.topView.deleButton.selected = commenModel.isZan;
    self.oneLabel.text = commenModel.oneText;
    self.numberLabel.text = [NSString stringWithFormat:@"%@  回复",commenModel.dataTime];
    self.authorLb.hidden = !commenModel.isAuthor;
}
-(void)createUI{
    
    self.oneLabel = UILabel.new;
    self.oneLabel.textColor = UIColorFromRGB(0x273323);
    self.oneLabel.font = SYSTEMFONT(14);
    self.oneLabel.numberOfLines = 0;
    self.oneLabel.text = @"这里是我的评论，大家来点赞！";
    
    self.numberLabel = UILabel.new;
    self.numberLabel.textColor = UIColorFromRGB(0x454F44);
    self.numberLabel.font = SYSTEMFONT(12);
    self.numberLabel.numberOfLines = 0;
    self.numberLabel.text = @"2019-04-19  15:30  24回复";
    
    
    [self addSubview:self.topView];
    [self addSubview:self.oneLabel];
    [self addSubview:self.numberLabel];
    [self addSubview:self.reportBtn];
    
    [self.topView addSubview:self.authorLb];
    
    
    [self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.mas_equalTo(0);
    }];
    
    [self.oneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(70);
        make.right.mas_equalTo(-16);
        make.top.mas_equalTo(self.topView.mas_bottom);
    }];
    
    [self.numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(70);
        make.right.mas_equalTo(-16);
        make.top.mas_equalTo(self.oneLabel.mas_bottom).offset(8);
        make.bottom.mas_equalTo(-16);
    }];
    [self.reportBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-16);
        make.centerY.mas_equalTo(self.numberLabel);
    }];
    
    
    [self.authorLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.topView.userName.mas_right).offset(10);
        make.centerY.mas_equalTo(self.topView.userName);
        make.width.mas_equalTo(28);
        make.height.mas_equalTo(16);
    }];
}
-(UserIconAndNameView*)topView{
    if(!_topView){
        _topView=[[UserIconAndNameView alloc] initWithFrame:CGRectZero];
        _topView.dynamicData.text = @"美食达人";
        [_topView.deleButton setImage:IMAGE_NAMED(@"ic_like_defut") forState:UIControlStateNormal];
        [_topView.deleButton setImage:IMAGE_NAMED(@"ic_like_selected1") forState:UIControlStateSelected];
        [_topView.deleButton setBackgroundImage:nil forState:UIControlStateNormal];
        [_topView.deleButton setTitle:@"13" forState:UIControlStateNormal];
        [_topView.deleButton setTitleEdgeInsets:UIEdgeInsetsMake(0, 4, 0, -4)];
        [_topView.deleButton setTitleColor:UIColorFromRGB(0x454F44) forState:UIControlStateNormal];
        _topView.deleButton.titleLabel.font = SYSTEMFONT(12);
        kWeakSelf(weakSelf);
        [_topView.deleButton addActionHandler:^{
            weakSelf.topView.deleButton.selected = !weakSelf.topView.deleButton.selected;
        }];
    }
    return _topView;
}
-(UILabel*)authorLb{
    if(!_authorLb){
        _authorLb=[UILabel new];
        _authorLb.textColor = UIColorFromRGB(0x2B77EC);
        _authorLb.font = BOLDSYSTEMFONT(11);
        _authorLb.text = @"作者";
        _authorLb.layer.borderColor =  UIColorFromRGB(0x2B77EC).CGColor;
        _authorLb.layer.borderWidth = 0.5;
        _authorLb.textAlignment = NSTextAlignmentCenter;
    }
    return _authorLb;
}
-(UIButton*)reportBtn{
    if(!_reportBtn){
        _reportBtn=[UIButton buttonWithType:UIButtonTypeCustom];
        [_reportBtn setTitleColor:UIColorFromRGB(0x959E97) forState:UIControlStateNormal];
        _reportBtn.titleLabel.font = SYSTEMFONT(12);
        [_reportBtn setTitle:@"举报" forState:UIControlStateNormal];
        _reportBtn.hidden = YES;
    }
    return _reportBtn;
}

@end


@interface AnswerDetailCommentsTitleCell ()
/**<#属性#>*/
@property (nonatomic,strong)UILabel * titelLabel;
/**<#属性#>*/
@property (nonatomic,strong)UILabel * numberLabel;
@end


@implementation AnswerDetailCommentsTitleCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;

        [self createUI];
    }
    return self;
}
-(void)setAnsTwoModel:(AnswerDetailTwoModel *)ansTwoModel{
    _ansTwoModel = ansTwoModel;
    self.titelLabel.text = ansTwoModel.title;
    self.numberLabel.text = [NSString stringWithFormat:@"%@个回答",ansTwoModel.answerNum];
}
-(void)createUI{
    self.titelLabel = UILabel.new;
    self.titelLabel.textColor = UIColorFromRGB(0x273323);
    self.titelLabel.font = BOLDSYSTEMFONT(18);
    self.titelLabel.text = @"西红柿炒蛋先放西红柿还是先放鸡蛋？";
    self.titelLabel.numberOfLines = 0;
    
    self.numberLabel = UILabel.new;
    self.numberLabel.textColor = UIColorFromRGB(0x959E97);
    self.numberLabel.font = BOLDSYSTEMFONT(12);
    self.numberLabel.text = @"12个回答";
    
    UIImageView * image = [[UIImageView alloc] initWithImage:IMAGE_NAMED(@"more")];
    
    [self addSubview:self.titelLabel];
    [self addSubview:self.numberLabel];
    [self addSubview:image];
    
    [self.titelLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_equalTo(16);
        make.right.mas_equalTo(-16);
    }];
    
    [self.numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.top.mas_equalTo(self.titelLabel.mas_bottom).offset(8);
        make.bottom.mas_equalTo(-16);
    }];
    [image mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.numberLabel.mas_right).offset(1);
        make.centerY.mas_equalTo(self.numberLabel);
    }];

}
@end

#import "EditAnswerController.h"


@interface AnswerDetailCommentsContexCell ()
/**用户视图*/
@property (nonatomic,strong)UserIconAndNameView*userView;
/**点赞、阅读数量*/
@property (nonatomic,strong)UILabel*rightNumlaber;
/**编辑按钮*/
@property (nonatomic,strong)UILabel*editorLabel;
/**<#属性#>*/
@property (nonatomic,strong)UILabel * context;
/**<#属性#>*/
@property (nonatomic,strong)UIImageView*conteImage;
/**<#属性#>*/
@property (nonatomic,strong)UILabel * context2;
@end


@implementation AnswerDetailCommentsContexCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;

        [self createUI];
    }
    return self;
}
-(void)setType:(AnswerDetailType)type{
    _type = type;
    if (type == AnswerDetailMe) {
        self.userView.deleButton.hidden = YES;
        self.rightNumlaber.hidden = NO;
        self.editorLabel.text = @"编辑";
    }
}
-(void)setAnsTwoModel:(AnswerDetailTwoModel *)ansTwoModel{
    _ansTwoModel = ansTwoModel;
    self.userView.userName.text = ansTwoModel.name;
    self.userView.iconImage.image = IMAGE_NAMED(ansTwoModel.userIcon);
    self.context.text = ansTwoModel.title;
    self.conteImage.image = IMAGE_NAMED(ansTwoModel.commentImage);
    self.context2.text = ansTwoModel.commentTex;
}
-(void)createUI{
    // MARK: ---正式对接后台数据的时候，这个位置可以替换成富文本显示不需要以下文本内容
    self.context = UILabel.new;
    self.context.textColor = UIColorFromRGB(0x454F44);
    self.context.font = SYSTEMFONT(14);
    self.context.text = @"一般我炒的时候，是先将鸡蛋打散，下锅炒至7成熟，盛出，倒油放西红柿翻炒至7成熟，导入刚刚炒好的鸡蛋，一起翻炒，出锅。 希望对你有用~";
    self.context.numberOfLines = 0;
    
    self.conteImage = UIImageView.new;
    self.conteImage.image = IMAGE_NAMED(@"dynamicDefut");
    
    UILabel * title2 = UILabel.new;
    title2.textColor = UIColorFromRGB(0x273323);
    title2.font = BOLDSYSTEMFONT(16);
    title2.text = @"相关问题";

    
    self.context2 = UILabel.new;
    self.context2.textColor = UIColorFromRGB(0x273323);
    self.context2.font = SYSTEMFONT(14);
    self.context2.text = @"怎么炒出一盘美味的西红柿炒蛋？/n 怎么炒出一盘美味的西红柿炒蛋？这个问题有点常常常常";
    self.context2.numberOfLines = 0;


    [self addSubview:self.userView];
    [self addSubview:self.context];
    [self addSubview:self.conteImage];
    [self addSubview:title2];
    [self addSubview:self.context2];
    
    [self addSubview:self.editorLabel];

    [self.userView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(0);
        make.left.right.mas_equalTo(0);
    }];
    [self.context mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.userView.mas_bottom).offset(0);
        make.left.mas_equalTo(16);
        make.right.mas_equalTo(-16);
    }];
    [self.conteImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.top.mas_equalTo(self.context.mas_bottom).offset(16);
        make.right.mas_equalTo(-16);
        make.height.mas_equalTo(238);
    }];
    [title2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.top.mas_equalTo(self.conteImage.mas_bottom).offset(16);
        make.right.mas_equalTo(-16);
    }];
    [self.context2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.top.mas_equalTo(title2.mas_bottom).offset(16);
        make.right.mas_equalTo(-16);
    }];
    [self.editorLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.context2.mas_bottom).offset(16);
        make.right.bottom.mas_equalTo(-16);
    }];


}
-(UserIconAndNameView*)userView{
    if(!_userView){
        _userView=[[UserIconAndNameView alloc] initWithFrame:CGRectZero];
        
        _userView.dynamicData.text = @"美食达人";
        [_userView.deleButton setBackgroundImage:IMAGE_NAMED(@"guanzhu_bg") forState:UIControlStateNormal];
        [_userView.deleButton setTitle:@"关注" forState:UIControlStateNormal];
        [_userView.deleButton setTitleColor:UIColorFromRGB(0xFFFFFF) forState:UIControlStateNormal];
        _userView.deleButton.titleLabel.font = SYSTEMFONT(14);
        [_userView.deleButton addActionHandler:^{
            
        }];
        [_userView addSubview:self.rightNumlaber];
        
        [self.rightNumlaber mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(-16);
            make.centerY.mas_equalTo(0);
        }];
    }
    return _userView;
}
-(UILabel*)rightNumlaber{
    if(!_rightNumlaber){
        _rightNumlaber=[UILabel new];
        _rightNumlaber.textColor = UIColorFromRGB(0x959E97);
        _rightNumlaber.font = SYSTEMFONT(12);
        _rightNumlaber.text = @"1234赞 1234阅读";
        _rightNumlaber.hidden = YES;
    }
    return _rightNumlaber;
}
-(UILabel*)editorLabel{
    if(!_editorLabel){
        _editorLabel=[UILabel new];
        _editorLabel.textColor = UIColorFromRGB(0x454F44);
        _editorLabel.font = SYSTEMFONT(14);
        _editorLabel.userInteractionEnabled = YES;
        [_editorLabel addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(pushEditorAction)]];
    }
    return _editorLabel;
}
-(void)pushEditorAction{
    [[self getCurrentViewController].navigationController pushViewController:[EditAnswerController new] animated:YES];
}
@end
